/*
 * Player.h
 *
 *  Created on: Oct 22, 2012
 *      Author: default
 */

#ifndef PLAYER_H_
#define PLAYER_H_
#include <MAUtil/Moblet.h>
#include <mastdlib.h>
#include <NativeUI/Widgets.h>
#include <ma.h>
#include <mavsprintf.h>
#include <NativeUI/WidgetUtil.h>
#include <MAUtil/Graphics.h>
#include "MAHeaders.h"

using namespace MAUtil;
using namespace NativeUI;


class Player : public MAUtil::TimerListener
{
	private:
		int Loc_x;          // The character’s location on the x-axis
		int Loc_y;          // The character’s location on the y-axis
		int Spd_x;          // The character’s speed in the x direction
		int Spd_y;          // The character’s speed in the y direction
		int Acc_x;          // The character’s acceleration in the x direction
		int Acc_y;          // The character’s acceleration in the y direction
		int Energy;         // The character’s energy which determines if he can accelerate
		enum ArmorColor {red, blue, green};          // 0 = red, 1 = blue, 2 = green
		ArmorColor Armor;
		bool Jumping;   // 0 = no, 1 = yes
		bool Sliding;     // 0 = no, 1 = yes

		int mScreenWidth, mScreenHeight;

		MARect flatman_srcRect;
		MAPoint2d flatman_dstPt;


	protected:


	public:
		Player()
		{
			Loc_x = 5;
			Loc_y = 15;
			Spd_x = 5;
			Spd_y = 0;
			Acc_x = 0;
			Acc_y = 0;
			Energy = 100;
			Armor = red;
			Jumping = 0;
			Sliding = 0;

			//draw();
			//addTimer(this, 50, -1);
		}

		Player(int lx, int ly, int sx, int sy, int ax, int ay, int e, int jump, int slide)
		{
			Loc_x = lx;
			Loc_y = ly;
			Spd_x = sx;
			Spd_y = sy;
			Acc_x = ax;
			Acc_y = ay;
			Energy = e;
			//Armor = arm;
			Jumping = jump;
			Sliding = slide;
		}

		int GetLoc_x()
		{
			return Loc_x;
		}

		int GetLoc_y()
		{
			return Loc_y;
		}

		int GetSpd_x()
		{
			return Spd_x;
		}

		int GetSpd_y()
		{
			return Spd_y;
		}

		int GetAcc_x()
		{
			return Acc_x;
		}

		int GetAcc_y()
		{
			return Acc_y;
		}

		int GetEnergy()
		{
			return Energy;
		}

		int GetArmor()
		{
			return Armor;
		}

		int GetJumping()
		{
			return Jumping;
		}

		int GetSliding()
		{
			return Sliding;
		}

		void SetLoc_x(int lx)
		{
			Loc_x = lx;
		}

		void SetLoc_y(int ly)
		{
			Loc_y = ly;
		}

		void SetSpd_x(int sx)
		{
			Spd_x = sx;
		}

		void SetSpd_y(int sy)
		{
			Spd_y = sy;
		}

		void SetAcc_x(int ax)
		{
			Acc_x = ax;
		}

		void SetAcc_y(int ay)
		{
			Acc_y = ay;
		}

		void SetEnergy(int e)
		{
			Energy = e;
		}

		void SetArmor(ArmorColor arm)
		{
			Armor = arm;
		}

		void SetJumping(bool jump)
		{
			Jumping = jump;
		}

		void SetSliding(bool slide)
		{
			Sliding = slide;
		}

		void IsJumping()
		{
			Jumping = true;
		}

		void NotJumping()
		{
			Jumping = false;
		}

		void IsSliding()
		{
			Sliding = true;
		}

		void NotSliding()
		{
			Sliding = false;
		}

		bool IsOnGround()
		{
			if (GetLoc_y() == mScreenWidth - 30)
				return true;
			else
				return false;
		}

		void draw()
			{
				// Draw flatman
			    flatman_srcRect.left = 94;
			    flatman_srcRect.top = 0;
			    flatman_srcRect.width = 93;
			    flatman_srcRect.height = 106;
			    //if (speed != 0) //running
			    //	boy_srcRect.top = 96;

			    flatman_srcRect.left += 93;
			    flatman_srcRect.left %= 199;
			    flatman_dstPt.x = Loc_x;
			    flatman_dstPt.y = Loc_y;
			    Loc_x += Spd_x;
			    Loc_y += Spd_y;
			    Gfx_drawImageRegion(FLATMAN, &flatman_srcRect, &flatman_dstPt, TRANS_NONE);


				maUpdateScreen();
			}

		void runTimerEvent()
			{


				Loc_x += Spd_x;
				Loc_y += Spd_y;



				// Call the function that draws the background and sprites.
				draw();

			}

};


#endif /* PLAYER_H_ */
